using System.Collections.Generic;

namespace K3Cloud.WebApi.Core.IoC.Extensions
{
    /// <summary>
    /// 表达式优化统计信息
    /// </summary>
    public class OptimizationStats
    {
        /// <summary>
        /// 优化前的节点数
        /// </summary>
        public int OriginalNodeCount { get; set; }

        /// <summary>
        /// 优化后的节点数
        /// </summary>
        public int OptimizedNodeCount { get; set; }

        /// <summary>
        /// 移除的冗余节点数
        /// </summary>
        public int RemovedNodeCount => OriginalNodeCount - OptimizedNodeCount;

        /// <summary>
        /// 优化率（百分比）
        /// </summary>
        public double OptimizationRate => OriginalNodeCount > 0 
            ? (double)RemovedNodeCount / OriginalNodeCount * 100 
            : 0;

        /// <summary>
        /// 应用的优化类型列表
        /// </summary>
        public List<string> OptimizationTypes { get; set; } = new List<string>();

        /// <summary>
        /// 优化耗时（毫秒）
        /// </summary>
        public double ElapsedMilliseconds { get; set; }

        /// <summary>
        /// 优化迭代次数
        /// </summary>
        public int IterationCount { get; set; }

        /// <summary>
        /// 是否发生了优化
        /// </summary>
        public bool HasOptimized => RemovedNodeCount > 0 || OptimizationTypes.Count > 0;

        /// <summary>
        /// 转换为字符串表示
        /// </summary>
        public override string ToString()
        {
            return $"优化统计: 节点数 {OriginalNodeCount}→{OptimizedNodeCount} " +
                   $"(减少{RemovedNodeCount}个, {OptimizationRate:F1}%), " +
                   $"耗时{ElapsedMilliseconds:F2}ms, " +
                   $"迭代{IterationCount}次, " +
                   $"应用规则: {string.Join(", ", OptimizationTypes)}";
        }
    }
}
